﻿@page "/htprintlist"
@rendermode InteractiveServer
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using HtERP.Data
@using ClosedXML.Excel
@inject IJSRuntime JS
@attribute [Authorize]

<PageTitle>HtPrintList</PageTitle>

<div>
    <strong><font size="5" style="color:#016f5e">数码印刷</font></strong>
    <em>（共: <strong>@numResults() </strong>条，数量: <strong>@TotalQuantity() </strong>，价格: <strong>@Totalprice()</strong>元。）</em>
    <button class="btn btn-primary" @onclick="DownloadExcel">下载Excel</button>
    <button class="btn btn-primary" @onclick="查询今天">今天</button>
    <button class="btn btn-primary" @onclick="查询昨天">昨天</button>
    <button class="btn btn-primary" @onclick="查询前天">前天</button>
</div>

<div>

    <input @bind="date1" id="tt" type="date" style="width:120px" />
    <input @bind="date2" id="tt" type="date" style="width:120px" />
    <input type="search" autofocus @bind="nameFilter" placeholder="客户..." style="width:120px" />
    <input type="search" autofocus @bind="nameFilter1" placeholder="工作名..." style="width:120px" />
    <input type="search" autofocus @bind="nameFilter2" placeholder="纸张类型..." style="width:120px" />
    <input type="search" autofocus @bind="nameFilter3" placeholder="要求说明..." style="width:120px" />
    <input type="search" autofocus @bind="nameFilter4" placeholder="送货地点..." style="width:120px" />
    <input type="search" autofocus @bind="nameFilter5" placeholder="制作员..." style="width:120px" />
    <button class="btn btn-primary" @onclick="查询">查询</button>
    <button class="btn btn-primary" @onclick="清空搜索项">清空搜索项</button>
</div>

<div>
    @if (items == null)
    {
        <p><em>Loading...</em></p>
    }
    else
    {
        <table class="table tablemini">
            <thead>
                <tr class="ttr">
                    <th><button class="btn trbtn" @onclick="@关闭子条目"><img src="/image/GreyLight.svg" width="18" /></button></th>
                    <th><button class="btn trbtn" @onclick="编号排序">编号<img src="@bhimg" width="18" alt="↓" /></button></th>
                    <th><button class="btn trbtn" @onclick="日期排序">日期<img src="@rqimg" width="18" alt="↓" /></button></th>
                    <th><button class="btn trbtn" @onclick="客户排序">客户<img src="@khimg" width="18" alt="↓" /></button></th>
                    <th>品名</th>
                    <th>纸张类型</th>
                    <th>印张</th>
                    <th>双面</th>
                    <th>要求说明</th>
                    <th>送货地点</th>
                    <th><button class="btn trbtn" @onclick="完成排序">完成</button></th>
                    <th>收费类别</th>
                    <th>单价</th>
                    <th style="background-color:rgb(185,225,185)">印刷费</th>
                    <th style="background-color:rgb(185,225,205)">设计费</th>
                    <th style="background-color:rgb(255,255,128)">应收价格</th>
                    <th>结清</th>
                    <th>制作员</th>
                    <th>备注</th>
                    <th>X</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var forecast in items)
                {
                    <tr>
                        <td><button class="btn trbtn" @onclick="@(() => 开关子条目(forecast.编号,forecast.后加工))"><img src="@修改图标(forecast.后加工)" width="18" alt="↓" /></button></td>
                        <td style="width:70px">@forecast.编号</td>
                        <td><input @bind="forecast.输出日期" id="日期" type="date" style="width:108px" @bind:after="@(() => 更新数据(forecast))" /></td>
                        <td>
                            <input @bind="forecast.客户" type="text" style="min-width:108px" @bind:after="@(() => 更新数据(forecast))" @onclick="khLoadList" list="options" />
                            <datalist id="options">
                                <option value="现金"></option>
                                <option value="临时"></option>
                                @if (kh != null) foreach (var fore in kh)
                                    {
                                        <option value="@fore.客户ID"></option>
                                    }
                                <!-- 更多选项 -->
                            </datalist>
                        </td>
                        <td><input @bind="forecast.文件或工作名" type="text" style="min-width:158px" @bind:after="@(() => 更新数据(forecast))" /></td>
                        <td>
                            <input @bind="forecast.纸张类型" type="text" style="width:118px;background-color:rgba(255,255,205,0.5)" @bind:after="@(() => 更新数据(forecast))" @onclick="zzLoadList" list="zzoptions" />
                            <datalist id="zzoptions">
                                @if (zzlist != null) foreach (var forzz in zzlist)
                                    {
                                        <option value="@forzz.类型"></option>
                                    }
                            </datalist>
                        </td>
                        <td><input @bind="forecast.张数" type="text" style="width:50px;text-align:right" @bind:after="@(() => 价格计算(forecast))" /></td>
                        <td><input @bind="forecast.双面" type="checkbox" style="width:28px" @bind:after="@(() => 更新数据(forecast))" /></td>
                        <td><input @bind="forecast.要求及文件位置" type="text" style="min-width:158px" @bind:after="@(() => 更新数据(forecast))" /></td>
                        <td><input @bind="forecast.送货地点" type="text" style="min-width:88px" @bind:after="@(() => 更新数据(forecast))" /></td>
                        <td><input @bind="forecast.已经发送" type="checkbox" style="width:28px" @bind:after="@(() => 更新数据(forecast))" /></td>
                        <td style="font-size: 0.8em">
                            <select @bind="forecast.收费类别" style="min-width:118px" @bind:after="@(() => 价格计算(forecast))" @onclick="sfLoadList">
                                <option value="自定单价">自定单价</option>
                                @if (sflist != null) foreach (var forsf in sflist)
                                    {
                                        <option value="@forsf.收费类别">@forsf.收费类别</option>
                                    }
                            </select>
                        </td>
                        <td><input @bind="forecast.阶梯价一" type="text" style="width:66px" @bind:after="@(() => 自定单价计算(forecast))" /></td>
                        <td>
                            <input type="number" style="text-align: right;width:68px;background-color:rgba(195,255,195,0.3)"
                                   value="@(forecast.印刷费?.ToString("F2") ?? "NULL")"
                                   @onchange="@(e => forecast.印刷费 = decimal.TryParse(e.Value?.ToString(), out decimal d) ? d : 0)"
                                   @onblur="@(() => 价格合计(forecast))"/>
                        </td>
                        <td>
                            <input type="number" style="text-align: right;width:68px"
                                   value="@(forecast.设计制作费?.ToString("F2") ?? "NULL")"
                                   @onchange="@(e => forecast.设计制作费 = decimal.TryParse(e.Value?.ToString(), out decimal d) ? d : 0)"
                                   @onblur="@(() => 价格合计(forecast))"/>
                        </td>
                        <td>
                            <input type="number" style="text-align: right; width:78px; background-color:rgba(255,255,188,0.5)" 
                                   value="@(forecast.应收?.ToString("F2") ?? "NULL")"
                                   @onchange="@(e => forecast.应收 = decimal.TryParse(e.Value?.ToString(), out decimal d) ? d : 0)"
                                   @onblur="@(() => 更新数据(forecast))"/>
                        </td>
                        <td><input @bind="forecast.结清" type="checkbox" style="width:36px;text-align:center" disabled /></td>
                        <td>
                            <input @bind="forecast.制作员1" type="text" style="width:80px" @bind:after="@(() => 更新数据(forecast))" @onclick="ygLoadList" list="ygoptions" />
                            <datalist id="ygoptions">
                                @if (yglist != null) foreach (var foryg in yglist)
                                    {
                                        <option value="@foryg.姓名"></option>
                                    }
                            </datalist>
                        </td>
                        <td><input @bind="forecast.备注" type="text" style="min-width:88px" @bind:after="@(() => 更新数据(forecast))" /></td>
                        <td style="width:20px"> <button class="btn trbtn" @onclick="@(() => ShowDeleteEvent(forecast))" style="color:red">删</button></td>
                    </tr>
                    @if (forecast.后加工==true)
                    {
                        <tr>
                            <td></td>
                            <td colspan="19">
                                <div>
                                    <HtPrintProcessing @bind-ChildDataId=@forecast.编号 @bind-ChildDataQty=@forecast.张数 @bind-ChildDataCust="@forecast.客户" @bind-ChildDataName="@forecast.文件或工作名" @bind-ChildDataShow="@forecast.要求及文件位置" />

                                </div>
                            </td>
                        </tr>
                    }

                }

            </tbody>
        </table>
    }
    <p> <button class="btn btn-primary" @onclick="新插一行">新建</button>   共: <strong>@numResults()</strong>条，印张合计: <strong>@TotalQuantity() </strong>，价格合计: <strong>@Totalprice()</strong>元</p>
</div>

@if (ShowDelete)
{
    <div class="custom-dialog" @onclick:stopPropagation>
        <div class="dialog-content">
            <h3> 是否确定要删除印刷单：</h3>
            <h4> @aa</h4>
            <p><button class="dialog-button" @onclick="Deleteit">确定删除</button> <button class="dialog-button" @onclick="HideDeleteEvent">取消</button></p>
        </div>
    </div>
}

@code {

    [CascadingParameter]
    private Task<AuthenticationState>? authenticationState { get; set; }

    AuthState? AuthState;

    DateTime date1 = DateTime.Now.AddDays(-1);
    DateTime date2 = DateTime.Now;

    private 数码印刷工作表[]? forecasts;

    IQueryable<数码印刷工作表>? items;

    string nameFilter = string.Empty;
    string nameFilter1 = string.Empty;
    string nameFilter2 = string.Empty;
    string nameFilter3 = string.Empty;
    string nameFilter4 = string.Empty;
    string nameFilter5 = string.Empty;

    private 客户[]? kh;
    private void khLoadList()
    {
        kh = HongtengDbCon.Db.Queryable<客户>().Where(it => it.IsDelete == false).ToArray();
    }

    public 员工[] yglist;
    private void ygLoadList()
    {
        yglist = HongtengDbCon.Db.Queryable<员工>().Where(it => it.是否已离职 != true).ToArray();
    }

    public 纸张类型[] zzlist;
    private void zzLoadList()
    {
        zzlist = HongtengDbCon.Db.Queryable<纸张类型>().ToArray();
    }

    public 数码印刷费率表[] sflist;
    private void sfLoadList()
    {
        sflist = HongtengDbCon.Db.Queryable<数码印刷费率表>().ToArray();
    }

    public int numResults()
    {
        int Count = items.Count();
        return Count;
    }

    public float? TotalQuantity()  //数量合计
    {
        float? total = items.Sum(item => item.张数);
        return total;
    }

    public decimal? Totalprice()  //价格合计
    {
        decimal? total = items.Sum(item => item.应收);
        return total;
    }


    protected override async Task OnInitializedAsync()
    {
        AuthState = authenticationState?.Result as AuthState;

        forecasts = HongtengDbCon.Db.Queryable<数码印刷工作表>().Where(it => it.输出日期.Value.Date == date2.Date).Where(it => it.IsDelete == false).ToArray();
        foreach (var forecast in forecasts)
        {
            forecast.后加工 = false;
        }
        items = forecasts.AsQueryable();
        await InvokeAsync(StateHasChanged);
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            sflist = HongtengDbCon.Db.Queryable<数码印刷费率表>().ToArray();
            await InvokeAsync(StateHasChanged);
        }

    }

    private void 更新数据(数码印刷工作表 p)
    {
        HongtengDbCon.Db.Updateable(p).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
    }

    private void 新插一行()
    {

        var ddd = HongtengDbCon.Db.Insertable(new 数码印刷工作表() { 客户 = "", 输出日期 = DateTime.Now, 制作员1 = AuthState?.UserName }).IgnoreColumns(ignoreNullColumn: true).ExecuteReturnEntity();
        var dda = forecasts.ToList();
        dda.Add(ddd);
        forecasts = dda.ToArray();
        items = forecasts.Where(it => it.IsDelete == false).AsQueryable();
    }


    private void 查询今天()
    {
        forecasts = HongtengDbCon.Db.Queryable<数码印刷工作表>().Where(it => it.输出日期.Value.Date == DateTime.Now.Date).Where(it => it.IsDelete == false).ToArray();
        items = forecasts.AsQueryable();
    }
    private void 查询昨天()
    {
        forecasts = HongtengDbCon.Db.Queryable<数码印刷工作表>().Where(it => it.输出日期.Value.Date == DateTime.Now.AddDays(-1).Date).Where(it => it.IsDelete == false).ToArray();
        items = forecasts.AsQueryable();
    }
    private void 查询前天()
    {
        forecasts = HongtengDbCon.Db.Queryable<数码印刷工作表>().Where(it => it.输出日期.Value.Date == DateTime.Now.AddDays(-2).Date).Where(it => it.IsDelete == false).ToArray();
        items = forecasts.AsQueryable();
    }

    private void 查询()
    {
        DateTime d1 = date1;
        DateTime d2 = date2;

        if (date2 < date1)
        {
            d1 = date2;
            d2 = date1;
        }

        forecasts = HongtengDbCon.Db.Queryable<数码印刷工作表>()
                .WhereIF(true, it => it.输出日期.Value.Date >= d1.Date && it.输出日期.Value.Date <= d2.Date)
                .WhereIF(!string.IsNullOrEmpty(nameFilter), it => it.客户.Contains(nameFilter))
                .WhereIF(!string.IsNullOrEmpty(nameFilter1), it => it.文件或工作名.Contains(nameFilter1))
                .WhereIF(!string.IsNullOrEmpty(nameFilter2), it => it.纸张类型.Contains(nameFilter2))
                .WhereIF(!string.IsNullOrEmpty(nameFilter3), it => it.要求及文件位置.Contains(nameFilter3))
                .WhereIF(!string.IsNullOrEmpty(nameFilter4), it => it.送货地点.Contains(nameFilter4))
                .WhereIF(!string.IsNullOrEmpty(nameFilter5), it => it.制作员1.Contains(nameFilter5)).ToArray();
        foreach (var forecast in forecasts)
        {
            forecast.后加工 = false;
        }
        items = forecasts.Where(it => it.IsDelete == false).AsQueryable();
    }

    private void 清空搜索项()
    {
        nameFilter = string.Empty;
        nameFilter1 = string.Empty;
        nameFilter2 = string.Empty;
        nameFilter3 = string.Empty;
        nameFilter4 = string.Empty;
        nameFilter5 = string.Empty;
    }

    //弹出窗口-软删除一条
    string? aa;
    public 数码印刷工作表? pp;
    public bool ShowDelete { get; set; }
    private void HideDeleteEvent()
    {
        ShowDelete = false;
    }
    private void ShowDeleteEvent(数码印刷工作表 p)
    {
        pp = p;
        aa = pp.编号 + "，" + pp.客户 + "【" + pp.文件或工作名 + "】";
        ShowDelete = true;
    }
    private void Deleteit()
    {
        pp.IsDelete = true;
        HongtengDbCon.Db.CurrentConnectionConfig.MoreSettings.IsCorrectErrorSqlParameterName = true; //局部生效兼容模式
        HongtengDbCon.Db.Updateable(pp).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
        items = forecasts.AsQueryable().Where(it => it.IsDelete == false);

        ShowDelete = false;
    }

    /// <summary>
    /// 排序
    /// </summary>
    int bh = 0;
    string bhimg = "/image/arrowUp.svg";
    private void 编号排序()
    {
        if (bh == 0)
        {
            items = items.OrderBy(p => p.编号).AsQueryable(); //顺序排序
            bh = 1;
            bhimg = "/image/arrowUp.svg";
        }
        else
        {
            items = items.OrderByDescending(p => p.编号).AsQueryable(); //倒叙排序
            bh = 0;
            bhimg = "/image/arrowDown.svg";
        }
    }

    int rq = 0;
    string rqimg = "/image/arrowUp.svg";
    private void 日期排序()
    {
        if (rq == 0)
        {
            items = items.OrderBy(p => p.输出日期).AsQueryable(); //顺序排序
            rq = 1;
            rqimg = "/image/arrowUp.svg";
        }
        else
        {
            items = items.OrderByDescending(p => p.输出日期).AsQueryable(); //倒叙排序
            rq = 0;
            rqimg = "/image/arrowDown.svg";
        }
    }

    int kk = 0;
    string khimg = "/image/arrowUp.svg";
    private void 客户排序()
    {
        if (kk == 0)
        {
            items = items.OrderBy(p => p.客户).AsQueryable(); //顺序排序
            kk = 1;
            khimg = "/image/arrowUp.svg";
        }
        else
        {
            items = items.OrderByDescending(p => p.客户).AsQueryable(); //倒叙排序
            kk = 0;
            khimg = "/image/arrowDown.svg";
        }
    }

    private void 完成排序()
    {
        items = items.OrderByDescending(p => p.已经发送).AsQueryable(); //排序
    }

    //关闭表格所有子条目
    private async Task 关闭子条目()
    {
        foreach (var forecast in items)
        {
            forecast.后加工 = false;
        }
    }

    //打开关闭表格子条目
    private async Task 开关子条目(int id, bool? yesno)
    {
        if (yesno==true)
        {
            items.Where(p => p.编号 == id).First().后加工 = false;
        }
        else
        {
            items.Where(p => p.编号 == id).First().后加工 = true;
        }
    }

    public string 修改图标(bool? yesno)
    {
        string imgsrc = "/image/triangleLeft.svg";
        if (yesno == true)
        {
            imgsrc = "/image/triangleDown.svg";
        }
        else
        {
            imgsrc = "/image/triangleLeft.svg";
        }
        return imgsrc;
    }

    public void 价格计算(数码印刷工作表 p)  //应收价格计算
    {
        decimal sjf = 0; //设计费
        decimal jg = 0; //印刷费
        decimal zs = 0; //张数
        decimal dj = 0; //单价
        decimal qbj = 0; //起步价
        decimal j1 = 5; //阶梯价一
        decimal j2 = 0; //阶梯价二
        decimal j3 = 0; //阶梯价三
        decimal j4 = 0; //阶梯价四
        int s1 = 0; //阶梯一档张数
        int s2 = 0; //阶梯二档张数
        int s3 = 0; //阶梯三档张数

        if (p.设计制作费 > 0)
        {
            sjf = p.设计制作费 ?? 0;
        }
        if (p.印刷费 > 0)
        {
            jg = p.印刷费 ?? 0;
        }
        if (p.张数 > 0)
        {
            zs = ((decimal)p.张数.Value);
        }
        if (p.阶梯价一 > 0)
        {
            dj = p.阶梯价一 ?? 0;
        }

        if (HongtengDbCon.Db.Queryable<数码印刷费率表>().Any(it => it.收费类别 == p.收费类别))
        {
            j1 = HongtengDbCon.Db.Queryable<数码印刷费率表>().First(it => it.收费类别 == p.收费类别).费率一 ?? 5; //如果价格为null则取值0
            j2 = HongtengDbCon.Db.Queryable<数码印刷费率表>().First(it => it.收费类别 == p.收费类别).费率二 ?? 0;
            j3 = HongtengDbCon.Db.Queryable<数码印刷费率表>().First(it => it.收费类别 == p.收费类别).费率三 ?? 0;
            j4 = HongtengDbCon.Db.Queryable<数码印刷费率表>().First(it => it.收费类别 == p.收费类别).费率四 ?? 0;
            qbj = HongtengDbCon.Db.Queryable<数码印刷费率表>().First(it => it.收费类别 == p.收费类别).起步价 ?? 0;
            s1 = HongtengDbCon.Db.Queryable<数码印刷费率表>().First(it => it.收费类别 == p.收费类别).一档张数 ?? 0;
            s2 = HongtengDbCon.Db.Queryable<数码印刷费率表>().First(it => it.收费类别 == p.收费类别).二档张数 ?? 0;
            s3 = HongtengDbCon.Db.Queryable<数码印刷费率表>().First(it => it.收费类别 == p.收费类别).三档张数 ?? 0;

            if (zs > 0) //张数大于0才计算
            {
                if (j2 == 0) //单一费率
                {
                    if (j1 * zs > qbj) //判断大于起步价
                    {
                        jg = j1 * zs; //应收价格
                        dj = j1; //单价
                    }
                    else
                    {
                        jg = qbj; //应收价格
                        dj = qbj / zs; //单价
                    }

                }
                if (j2 > 0 & j3 == 0) //二段费率
                {
                    if (zs > s1) //总张数大于一档张数
                    {
                        jg = j1 * s1 + j2 * (zs - s1);
                        if (jg < qbj) //起步价
                        {
                            jg = qbj;
                        }
                        dj = jg / zs;
                    }
                    else
                    {
                        jg = j1 * zs;
                        if (jg < qbj) //起步价
                        {
                            jg = qbj;
                        }
                        dj = jg / zs;
                    }
                }
                if (j2 > 0 & j3 > 0 & j4 == 0) //三段费率
                {
                    if (zs>s1)
                    {
                        if (zs > s1+s2)
                        {
                            jg = j1 * s1 + j2 * s2 + j3 * (zs - s1-s2);
                            if (jg < qbj) //起步价
                            {
                                jg = qbj;
                            }
                            dj = jg / zs;
                        }
                        else
                        {
                            jg = j1 * s1 + j2 * (zs - s1);
                            if (jg < qbj) //起步价
                            {
                                jg = qbj;
                            }
                            dj = jg / zs;
                        }
                    }
                    else
                    {
                        jg = j1 * zs;
                        if (jg < qbj) //起步价
                        {
                            jg = qbj;
                        }
                        dj = jg / zs;
                    }
                }
                if (j2 > 0 & j3 > 0 & j4 > 0) //四段费率
                {
                    if (zs > s1)
                    {
                        if (zs > s1 + s2)
                        {
                            if (zs > s1 + s2 + s3)
                            {
                                jg = j1 * s1 + j2 * s2 + j3 * s3 + j4*(zs-s1-s2-s3);
                                if (jg < qbj) //起步价
                                {
                                    jg = qbj;
                                }
                                dj = jg / zs;
                            }
                            else
                            {
                                jg = j1 * s1 + j2 * s2 + j3 * (zs - s1 - s2);
                                if (jg < qbj) //起步价
                                {
                                    jg = qbj;
                                }
                                dj = jg / zs;
                            }

                        }
                        else
                        {
                            jg = j1 * s1 + j2 * (zs - s1);
                            if (jg < qbj) //起步价
                            {
                                jg = qbj;
                            }
                            dj = jg / zs;
                        }
                    }
                    else
                    {
                        jg = j1 * zs;
                        if (jg < qbj) //起步价
                        {
                            jg = qbj;
                        }
                        dj = jg / zs;
                    }
                }

                p.印刷费 = jg;
                p.阶梯价一 = dj;
                p.阶梯价二 = dj;
                p.起步价 = qbj;
                p.应收 = jg + sjf;
            }

        }
        else
        {
            p.印刷费 = zs * dj;
            p.应收 = p.印刷费 + sjf;
        }
        HongtengDbCon.Db.Updateable(p).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
    }

    public void 自定单价计算(数码印刷工作表 p)  //应收价格计算
    {
        decimal sjf = 0; //设计费
        decimal zs = 0; //张数
        if (p.设计制作费 > 0)
        {
            sjf = p.设计制作费 ?? 0;
        }
        if (p.张数 > 0)
        {
            zs = ((decimal)p.张数.Value);
        }
        p.印刷费 = p.阶梯价一 * zs;
        p.应收 = p.印刷费 + sjf;
        p.收费类别 = "自定单价";
        HongtengDbCon.Db.Updateable(p).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
    }

    public void 价格合计(数码印刷工作表 p)  //应收价格计算
    {
        decimal sjf = 0; //设计费
        decimal jg = 0; //印刷费
         if (p.设计制作费 > 0)
        {
            sjf = p.设计制作费 ?? 0;
        }
        if (p.印刷费 > 0)
        {
            jg = p.印刷费 ?? 0;
        }
        p.应收 = sjf + jg;
        HongtengDbCon.Db.Updateable(p).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
    }

    // 导出Excel文件
    public async Task DownloadExcel()
    {
        using (XLWorkbook workbook = new XLWorkbook())
        {
            IXLWorksheet worksheet = workbook.AddWorksheet("Mysheet");

            worksheet.Cell(1, 1).Value = "完成";
            worksheet.Cell(1, 2).Value = "编号";
            worksheet.Cell(1, 3).Value = "日期";
            worksheet.Cell(1, 4).Value = "客户";
            worksheet.Cell(1, 5).Value = "工作名";
            worksheet.Cell(1, 6).Value = "数量";
            worksheet.Cell(1, 7).Value = "纸张类型";
            worksheet.Cell(1, 8).Value = "价格";
            worksheet.Cell(1, 9).Value = "要求";
            worksheet.Cell(1, 10).Value = "送货地址";
            worksheet.Cell(1, 11).Value = "制作员";
            worksheet.Cell(1, 12).Value = "备注";

            worksheet.Row(1).Style.Font.Bold = true;


            int row = 2;
            foreach (var forzz in items)
            {
                worksheet.Cell(row, 1).Value = forzz.已经发送.ToString();
                worksheet.Cell(row, 2).Value = forzz.编号.ToString();
                worksheet.Cell(row, 3).Value = forzz.输出日期;
                worksheet.Cell(row, 4).Value = forzz.客户;
                worksheet.Cell(row, 5).Value = forzz.文件或工作名;
                worksheet.Cell(row, 6).Value = forzz.张数;
                worksheet.Cell(row, 7).Value = forzz.纸张类型;
                worksheet.Cell(row, 8).Value = forzz.应收;
                worksheet.Cell(row, 9).Value = forzz.要求及文件位置;
                worksheet.Cell(row, 10).Value = forzz.送货地点;
                worksheet.Cell(row, 11).Value = forzz.制作员1;
                worksheet.Cell(row, 12).Value = forzz.备注;
                row++;
            }

            // 创建内存流用于保存工作簿
            using (var memoryStream = new MemoryStream())
            {
                // 将工作簿保存到内存流中
                workbook.SaveAs(memoryStream);

                // 重置内存流的位置，以确保从头开始读取
                memoryStream.Position = 0;

                // 这里可以将内存流进行进一步处理，例如发送为电子邮件附件或者作为API响应返回等
                var fileName = "印刷"+DateTime.Now.ToString()+".xlsx";

                using var streamRef = new DotNetStreamReference(stream: memoryStream);

                await JS.InvokeVoidAsync("downloadFileFromStream", fileName, streamRef);
            }
        }

    }

}
